﻿/*
 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
 */

#ifndef PARAMSETTINGDLG_H
#define PARAMSETTINGDLG_H

#include <QMainWindow>
#include <QSettings>
#include <QTextCodec>
#include "BurnCtrl/BurnCtrl.h"
#include "ui_ParamSettingDlg.h"

namespace BurnDlg {

class ParamSettingDlg : public QMainWindow {
    Q_OBJECT
public:
    explicit ParamSettingDlg(QWidget *parent = nullptr);
    ~ParamSettingDlg() override;

    void ShowTable(QString group);
    void ShowInfoAreaUI(bool isEnable) const;
    void SetBurnCtrl(BurnCtrl *burnCtrlNeedSet);
    bool GetinfoUnlockData(const QSettings *fd);
    void SetTransmissionMode(QString str);
    bool IsSetParameter();
    void SetChipMode(int chip);
    void GetParameterBaseInfo();
    void GetProtectionPara();
    void SetParameterEnableValue(QString group);
    void SetCurrentPath();
    void SetIniSettings(QSettings *fd);
    void SetIsConnect(bool connect);
    void ShowQComboBox(QSettings *fd, QString group, QComboBox *qBox, int baseSystem) const;
public slots:
    void SlotParameterSavePathButClicked();
    void SlotGetParameterInfoClicked();
    void SlotSetParameterInfoList(QByteArray byte);
    void SlotSetParameterInfoClicked();
    void SlotParameterSave();
    void SlotParameterSavePathTextChange(const QString &str);
    void SlotSetInfoAreaValue(QString value);
signals:
    void SignalGetParameter();
    void SignalSetParameter();
    void SignalSetLog(QString logs, bool isShowTime, QColor color);
protected:
    void InitUi();
    void SetTableWidgetValue(ParameterInfo &parameter, int rowCount, int index) const;
    void SetTableWidgetItemValue(QStringList &vals, int index, int rowCount) const;
    void SetProtectionPara(int index);
    void SetParameterInfoListNewValue(int row);
    void GetConfigurationParameterData();
    bool IsNOMoreThanMaxValue(QString &key, DWORD &value, QString &parameterName, DWORD &maxValue);
    bool InfoSavaParameterRule(QString &parameterName, DWORD &maxValue);
    bool IsSetDisableMode();
    bool GetUnlockParameter();
    bool GetParameterToBuff(QStringList &lockNames, QStringList &changeName,
                            QBitArray &bits, int &unlockOffset,
                            bool &isChange);
    void SetBitValue(ParameterInfo info, QBitArray &bits,
        int &offset, const uint &newValue, int &totalOffset) const;
    void SetMapBuf(QBitArray bits, int unlockOffset, bool lock, bool isChange);
    int GetParameterData();
    void UpdatesParameterTable();

private:
    void FormUiParameterTableItems(const QString &group, QStringList &keys);
private:
    Ui::ParamSettingDlg *ui;
    int totalDigits = 0;
    QTextCodec *codec = nullptr;
    QString parameterFilePath = "";                   /* parameter configuration file path */
    BurnCtrl *burnCtrl = nullptr;
    QList <ParameterInfo> parameterInfoList;    /* Argument Array */
    bool isInitParameter = true;
    ParameterInfo protectionPara;               /* Protection parameters */
    QList <ParameterInfo> infoUnlockList;
    QSettings *chipIniRead;
    QString transmissionMode;
    int chipMode;
    QList <ParameterBuff> mapBuf;
    ulong parameterStartAddress;
    ulong lockStartAddress;
    ulong eraseBaseNum;
    QString currentPath;
    MyStringClass::StringClass stringClass;
    QString currentInfo;
    bool isConnect;
};

}
#endif // PARAMSETTINGDLG_H
